package com.c1.client.dialog.r.util;

/**
 * @author zhangjiangnan
 */
public class SinaRemote {
    public static String getMinImageUrl(String code, String tsCode) {
        return getImageUrl(code, tsCode, ImageType.type.MIN_IMAGE);
    }

    public static String getDailyImageUrl(String code, String tsCode) {
        return getImageUrl(code, tsCode, ImageType.type.DAIlY_IMAGE);
    }

    private static String getImageUrl(String code, String tsCode, ImageType.type imageType) {
        String type = ImageType.getUrl(imageType);
        return type + tsCode.substring(tsCode.indexOf(".") + 1).toLowerCase() + code + ".gif?a=" + System.currentTimeMillis();
    }

    private static class ImageType {
        private enum type {
            MIN_IMAGE, DAIlY_IMAGE, WEEKLY_IMAGE, MONTHLY_IMAGE
        }

        private static final String SINA_MINIMG = "http://image.sinajs.cn/newchart/min/n/";
        private static final String SINA_DAILYIMG = "http://image.sinajs.cn/newchart/daily/n/";
        private static final String SINA_WEEKLYIMG = "http://image.sinajs.cn/newchart/weekly/n/";
        private static final String SINA_MONTHLYIMG = "http://image.sinajs.cn/newchart/monthly/n/";

        private static String getUrl(ImageType.type imageType) {
            if (imageType == ImageType.type.MIN_IMAGE) {
                return SINA_MINIMG;
            }
            if (imageType == ImageType.type.DAIlY_IMAGE) {
                return SINA_DAILYIMG;
            }
            if (imageType == ImageType.type.WEEKLY_IMAGE) {
                return SINA_WEEKLYIMG;
            }
            if (imageType == ImageType.type.MONTHLY_IMAGE) {
                return SINA_MONTHLYIMG;
            }
            return null;
        }
    }
}
